package se.chalmers.tda366.crumble.gui.components;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle;

import se.chalmers.tda366.crumble.core.IArticle;
import se.chalmers.tda366.crumble.gui.utils.IArticleLink;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ArticlePreviewPanel extends JPanel implements IArticleLink{
	private JTextPane contentTextArea;
	private JLabel headlineLabel;
	//private JButton headlineButton;
	private IArticle article;

	public ArticlePreviewPanel (IArticle article) {
		this.article=article;
		initGUI(article);
		addMouseListener(new se.chalmers.tda366.crumble.gui.utils.CrumbleMouseListener());
	}
	
	private void initGUI(IArticle article) {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			this.setBackground(new java.awt.Color(255,255,255));
			this.setFocusTraversalKeysEnabled(false);
			{
				headlineLabel = new JLabel();
				headlineLabel.setText("Lorem Ipsum"); //dummy text for formatting purpuses
				headlineLabel.setText(article.getHeadline());
				headlineLabel.setFont(se.chalmers.tda366.crumble.resources.Constants.HEADLINEFONT);

			}
			{
				contentTextArea = new JTextPane();
				contentTextArea.setEditable(false);
				contentTextArea.setOpaque(false);
				contentTextArea.setBackground(new java.awt.Color(255,255,255));
				contentTextArea.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				contentTextArea.setText("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor " +
						"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation " +
						"ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in " +
						"voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " +
						"proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");//dummy text for formatting purpuses
				contentTextArea.setContentType("text/html");
				contentTextArea.setText(se.chalmers.tda366.crumble.utils.ImageStripper.strip(article.getDescription()));
				contentTextArea.setFont(se.chalmers.tda366.crumble.resources.Constants.BODYTEXT);
				//contentTextArea.addMouseListener(new crumble.utils.CrumbleMouseListener());
			}
				thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
					.addComponent(headlineLabel, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
					.addComponent(contentTextArea, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE));
				thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(thisLayout.createParallelGroup()
					    .addComponent(headlineLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 410, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
					        .addComponent(contentTextArea, 0, 385, Short.MAX_VALUE)
					        .addGap(25))));
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public IArticle getArticle(){
		return article;
	}
	
}
